<script type="text/javascript">
function showOrHide(id) {
	var table = $('#handle_table_' + id);
	if (table.is(":visible")) table.hide();
	else table.show();
}

function editHandle(code, parentCode, type) {
	var url = create_url('handle-edit');
	var parm = {'code':(null != code ? code : ''), 'parentCode':(null != parentCode ? parentCode : ''), 'type':(null != type ? type : 'HANDLE')};
	sys_loading();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#editHandleTd').html(result);
		}
	});
}

function deleteHandle(code, name) {
	ui.confirm('删除操作', '确认要删除名称为：' + name + ' 的操作吗?')
		.ok('确认删除')
		.cancel('取消')
		.show(function(ok){
			if (ok) {
				sys_submiting();
				var url = '${contextPath}handle-delete.html?time=' + getTime();
				var parm = {'code':code};
				$.ajax({type:'POST', url:url, data:parm, 
					success: function(result) {
						sys_submiting_close();
						if ('success' == result) {
							sys_msg(name + ' 操作删除成功!');
							loadHandlePage('handle-list');
						} else {
							sys_warning('删除失败', name + ' 操作删除失败，请联系管理员!');
						}
					}
				});
			}
		});
}

$(function () {
	editHandle(null, 0, 'MODULE');
});
</script>
<table class="handle_info"><tr>
	<th>&nbsp;&nbsp;&nbsp;&nbsp;<img src="${contextPath}images/icon/img_734.gif" />&nbsp;&nbsp;系统管理&nbsp;&nbsp;&#8250;&nbsp;&nbsp;操作管理</th>
	<td><img src="${contextPath}images/icon/img_609.gif" />&nbsp;添加子操作&nbsp;&nbsp;&nbsp;&nbsp;
		<img src="${contextPath}images/icon/img_614.gif" />&nbsp;编辑&nbsp;&nbsp;&nbsp;&nbsp;
		<img src="${contextPath}images/icon/img_613.gif" />&nbsp;删除&nbsp;&nbsp;&nbsp;&nbsp;
	</td></tr></table>
	
<#import "/freemarker/modeltype.ftl" as mt>

<div>
<table style="width:100%; min-height:500px;">
	<tr>
		<td style="vertical-align:top; width:620px;">
			<table cellpadding="1" cellspacing="1" class="result_list_table" style="width:600px; float:left;">
				<tr class="ui-widget-header">
					<th>ID</th>
					<th>名称</th>
					<th>父操作名称</th>
					<th>相对路径</th>
					<th>类型</th>
					<th>是否删除</th>
					<th style="width: 80px;">操作</th>
				</tr>
				<#list list as mo>
				<tr class="ui-widget-content">
					<td>${mo.code}</td>
					<td><a href="#" onclick="javascript: showOrHide(${mo.code}); return false;">${mo.name}</a></td>
					<td>${mo.parentName}</td>
					<td>${mo.url}</td>
					<td><@mt.HandleType value=((mo.type)!"") r=false /></td>
					<td><@mt.YesOrNo value=((mo.deleted)!false) r=false /></td>
					<td style="width:80px;">
						<a href="#" onclick="javascript: editHandle(null, ${mo.code}, 'MENU'); return false;">
							<img src="${contextPath}images/icon/img_609.gif" /></a>
						<a href="#" onclick="javascript: editHandle(${mo.code}); return false;">
							<img src="${contextPath}images/icon/img_614.gif" /></a>
						<a href="#" onclick="javascript: deleteHandle('${mo.code}', '${mo.name}'); return false;">
							<img src="${contextPath}images/icon/img_613.gif" /></a>
					</td>
				</tr>
				<#if ((mo.sonList)?? && mo.sonList?size > 0)>
				<tr>
					<td colspan="7" style="height:0px;">
						<table id="handle_table_${mo.code}" style="display:none; width:575px; float:right; margin-right:-7px;">
							<#list mo.sonList as me>
							<tr class="ui-widget-content">
								<td>${me.code}</td>
								<td><a href="#" onclick="javascript: showOrHide(${me.code}); return false;">${me.name}</a></td>
								<td>${me.parentName}</td>
								<td>${me.url}</td>
								<td><@mt.HandleType value=((me.type)!"") r=false /></td>
								<td><@mt.YesOrNo value=((me.deleted)!false) r=false /></td>
								<td style="width:80px;">
									<a href="#" onclick="javascript: editHandle(null, ${me.code}, 'HANDLE'); return false;">
										<img src="${contextPath}images/icon/img_609.gif" /></a>
									<a href="#" onclick="javascript: editHandle(${me.code}); return false;">
										<img src="${contextPath}images/icon/img_614.gif" /></a>
									<a href="#" onclick="javascript: deleteHandle('${me.code}', '${me.name}'); return false;">
										<img src="${contextPath}images/icon/img_613.gif" /></a>
								</td>
							</tr>
							<#if ((me.sonList)?? && me.sonList?size > 0)>
								<tr><td colspan="7" style="height:0px;">
									<table id="handle_table_${me.code}" style="display:none; width:550px; float:right; margin-right:-7px;">
										<#list me.sonList as h>
										<tr class="ui-widget-content">
											<td>${h.code}</td>
											<td>${h.name}</td>
											<td>${h.parentName}</td>
											<td>${h.url}</td>
											<td><@mt.HandleType value=((h.type)!"") r=false /></td>
											<td><@mt.YesOrNo value=((h.deleted)!false) r=false /></td>
											<td>
												<a href="#" onclick="javascript: editHandle(${h.code}); return false;">
													<img src="${contextPath}images/icon/img_614.gif" /></a>
												<a href="#" onclick="javascript: deleteHandle('${h.code}', '${h.name}'); return false;">
													<img src="${contextPath}images/icon/img_613.gif" /></a>
											</td>
										</tr>
										</#list>
									</table>
								</td></tr>
							</#if>
							</#list>
						</table>
					</td>
				</tr>
				</#if>
				</#list>
			</table>
		</td>
		<td id="editHandleTd" style="vertical-align:top;"></td>
	</tr>
</table>
